package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.MGoodsEntity;
import com.company.project.service.MGoodsService;
import org.springframework.web.multipart.MultipartFile;


/**
 * 商品详细表
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2021-09-01 06:54:56
 */
@Controller
@RequestMapping("/")
public class MGoodsController {
    @Autowired
    private MGoodsService mGoodsService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/mGoods")
    public String mGoods() {
        return "mgoods/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("mGoods/add")
    @RequiresPermissions("mGoods:add")
    @ResponseBody
    public DataResult add(@RequestBody MGoodsEntity mGoods){
        mGoodsService.save(mGoods);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("mGoods/delete")
    @RequiresPermissions("mGoods:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        mGoodsService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("mGoods/update")
    @RequiresPermissions("mGoods:update")
    @ResponseBody
    public DataResult update(@RequestBody MGoodsEntity mGoods){
        mGoodsService.updateById(mGoods);
        return DataResult.success();
    }

    @ApiOperation(value = "导入")
    @PutMapping("mGoods/importGoods")
    @RequiresPermissions("mGoods:importGoods")
    @ResponseBody
    public DataResult importGoods(MultipartFile file){
        mGoodsService.importGoods(file);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("mGoods/listByPage")
    @RequiresPermissions("mGoods:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody MGoodsEntity mGoods){
        Page page = new Page(mGoods.getPage(), mGoods.getLimit());
        LambdaQueryWrapper<MGoodsEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(MGoodsEntity::getId, mGoods.getId());
        IPage<MGoodsEntity> iPage = mGoodsService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
